package com.lcj.aoch.rule.controller;

import com.lcj.aoch.rule.config.ConstantConfiguration;
import com.lcj.aoch.rule.controller.form.CalculateProfitsharingForm;
import com.lcj.aoch.rule.controller.form.SearchProfitsharingRuleByIdForm;
import com.lcj.aoch.rule.service.ProfitsharingRuleService;
import com.lcj.common.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/profitsharing"})
@Tag(name = "ProfitsharingRuleController", description = "分账规则Web接口")
public class ProfitsharingRuleController {

  @Resource
  private ProfitsharingRuleService profitsharingRuleService;

  @Resource
  private ConstantConfiguration constantConfiguration;
  
  @PostMapping({"/searchProfitsharingRuleById"})
  @Operation(summary = "根据ID查询分账规则")
  public Result searchProfitsharingRuleById(@RequestBody @Valid SearchProfitsharingRuleByIdForm searchProfitsharingRuleByIdForm) {
    return Result.ok().put("result", this.profitsharingRuleService.searchProfitsharingRuleById(searchProfitsharingRuleByIdForm.getRuleId().longValue()));
  }
  
  @PostMapping({"/calculateProfitsharing"})
  @Operation(summary = "计算分账规则")
  public Result calculateProfitsharing(@RequestBody @Valid CalculateProfitsharingForm calculateProfitsharingForm) {
    return Result.ok().put("result",
            this.profitsharingRuleService.calculateProfitsharing(
                    calculateProfitsharingForm.getOrderId().longValue(),
                    calculateProfitsharingForm.getAmount(),
                    constantConfiguration.getAesKey()));
  }
}
